class Solution {
public:
    bool isNumber(string s){
        s += '\0';   //指针移动过程中，最后会有一位的溢出，加上一位空字符防止字符串下标越界
        bool point = 0, e = 0;
        int len = s.size();
        cout << len << endl;

        int i = 0;

        while(s[i] == ' ')  i++;
        cout << "s[" << i << "] = " << s[i] << endl;

        //正儿八经首位的情况
        if(s[i] == 'e' || s[i] == 'E')   return 0;
        //判断正负号情况
        else if(s[i] == '+' || s[i] == '-' ) i = i;
        //判断小数点情况
        else if( s[i] == '.') point = 1;
        else if(s[i] <= '9' && s[i] >= '0')  i = i;
        else    return 0;
        i++;

        //cout << "跳过了首位" << endl;

        //循坏后续
        while(i < len){
            //cout << "s[" << i << "] = " << s[i] << endl;
            //整数直接快进
            while(s[i] <= '9' && s[i] >= '0') { 
                i++;
            }
            //判断是否为带e型
            if(s[i] == 'e' || s[i] == 'E'){
                if(e)   return 0;   //之前出现过e,直接返回0
                //如果e后面接了正负号，进行判断
                if(s[i + 1] == '+' || s[i + 1] == '-'){
                    e = 1;  //标记存在e
                    i++;
                }
                e = 1;
            }
            //判断小数点情况
            if(s[i] == '.'){
                //如果之前出现过.,直接返回0
                if(point)  return 0;
                //如果已经有e了，后续不能接小数
                if(e)   return 0;
                point = 1;
            }
        }
        return 1;
    }
};



